package code.google.model.player.states;

import java.io.IOException;

import code.google.model.util.interfaces.ISong;

public class IdleLocalState extends State {

	public IdleLocalState(StateManager manager) {
		super(manager);
	}

	@Override
	public boolean play(ISong song) {
		 try {
			player.setDataSource(song.getFilePath());
			player.setOnPreparedListener(manager.getPreparingLocalState());
			player.setOnCompletionListener(manager.getPlayingLocalState());
			manager.setCurrentState(manager.getPreparingLocalState());
			player.prepareAsync();
			return true;
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
			return false;
		} catch (SecurityException e) {
			e.printStackTrace();
			return false;
		} catch (IllegalStateException e) {
			e.printStackTrace();
			return false;
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
	}

}
